package avicit.bdp.dcs.semistructure.rest;

import avicit.bdp.dcs.semistructure.dto.AsyncFileDTO;
import avicit.bdp.dcs.semistructure.service.AsyncFileService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @金航数码科技有限责任公司
 * @作者：liyb
 * @邮箱：liyb@avic-digital.com
 * @创建时间：2021-03-17 15:09
 * @类说明：异步文件删除接口
 * @修改记录：
 */
@RestController
@RequestMapping("/api/bdp/dcs/file/AsyncFileRest")
@Api(tags = "异步文件删除接口")
public class AsyncFileRest {

    private static final Logger logger = LoggerFactory.getLogger(AsyncFileRest.class);

    @Autowired
    private AsyncFileService asyncFileService;

    @GetMapping("/getFileList")
    @ApiOperation(value = "查询文件列表")
    public ResponseMsg<QueryRespBean<AsyncFileDTO>> getFileList(@ApiParam(value = "状态", name = "status") @RequestParam(required = false) Integer status,
                                                                @ApiParam(value = "文件路径", name = "filePath") @RequestParam(required = false) String filePath,
                                                                @ApiParam(value = "文件名称", name = "fileName") @RequestParam(required = false) String fileName,
                                                                @ApiParam(value = "当前页", name = "currentPage", required = true)  @RequestParam(defaultValue = "1") Integer currentPage,
                                                                @ApiParam(value = "每页显示条数", name = "pageSize", required = true) @RequestParam(defaultValue = "10") Integer pageSize) throws Exception{
        ResponseMsg<QueryRespBean<AsyncFileDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<AsyncFileDTO> queryRespBean = asyncFileService.getFileList(status, filePath, fileName, currentPage, pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @PostMapping("/deleteFileData")
    @ApiOperation(value = "删除文件数据")
    public ResponseMsg<Boolean> deleteFileData(@RequestBody AsyncFileDTO asyncFileDTO)  throws Exception{
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(asyncFileService.deleteFileData(asyncFileDTO.getId()));
        return responseMsg;
    }

}
